from api05 import *
import pprint

login,cookies=login('auto','sdfsdfsdf')
print('登陆成功')

sessionid =cookies['sessionid']


#列出课程
coureListBefore = list_course(sessionid)['retlist']

retobj = add_course('python','python语言','2',sessionid)
assert  retobj['retcode'] == 0

if retobj['retcode'] == 0:
    print('添加课程成功')
else:
    raise Exception('添加课程失败')


#添加课程后列出课程
aftercourse=list_course(sessionid)['retlist']

createCount = len(aftercourse) - len(coureListBefore)
assert createCount == 1

newcourse = None
for one in aftercourse:
    if one not in coureListBefore:
        newcourse = one


assert newcourse['name']=='python'
assert newcourse['desc']=='python语言'
assert newcourse['display_idx']== 2

# 清除环境操作
delete_course(newcourse['id'],sessionid)

print('\n========= test case pass =============')
